import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import '../../../app_files.dart';
import 'action.dart';
import 'state.dart';
import '../../../PublicSource/widgets/fileimage_ex.dart';

Widget buildView(
    UserEditInfoViewState state, Dispatch dispatch, ViewService viewService) {
  List<String> _titles = [
    '昵称',
    '联系方式',
    '性别',
//    '职业',
//    '生日',
  ];
  List<String> _values = [
    state.nickName.length == 0 ? '请设置昵称' : state.nickName,
    GlobalStore.store.getState().userInfo.mobile,
    state.sex == null ? '请选择' : state.sex ? '女' : '男',
  ];

  Widget _body() {
    List<Widget> _items = [];
    for (int i = 0; i < _titles.length; ++i) {
      Widget _container = InkWell(
        child: Container(
          padding: EdgeInsets.symmetric(horizontal: 15),
          height: 51,
          child: Row(
            children: <Widget>[
              Text(
                _titles[i],
                style: TextThemeConfig.Font14WithColor22,
              ),
              Expanded(child: Container()),
              Padding(
                padding: EdgeInsets.only(right: i == 1 ? 0 : 8),
                child: Text(
                  _values[i],
                  style: TextThemeConfig.Font14WithColor99,
                ),
              ),
              i == 1 ? Container() : Image.asset('images/right_arrow.png'),
            ],
          ),
          decoration: BoxDecoration(
            color: Colors.white,
            border: Border(bottom: BorderSide(color: ThemeConfig.separeColor)),
          ),
        ),
        onTap: () => dispatch(UserEditInfoViewActionCreator.onTap(_titles[i])),
      );
      _items.add(_container);
    }

    Widget _headWidget = InkWell(
      child: Container(
        padding: EdgeInsets.symmetric(horizontal: 15),
        height: 51,
        child: Row(
          children: <Widget>[
            Text(
              '头像',
              style: TextThemeConfig.Font14WithColor22,
            ),
            Expanded(child: Container()),
            ClipRRect(
              borderRadius: BorderRadius.all(Radius.circular(16.5)),
              child: FadeInImage(
                placeholder: AssetImage("images/default_head.png"),
                fit: BoxFit.fill,
                image: state.selectImage == null
                    ? CachedNetworkImageProvider(
                        NetworkConfig.imageUrl(state.userHead))
                    : FileImageEx(state.selectImage),
                width: 33,
                height: 33,
              ),
            ),
            Padding(padding: EdgeInsets.only(left: 8)),
            Image.asset('images/right_arrow.png'),
          ],
        ),
        decoration: BoxDecoration(
          color: Colors.white,
          border: Border(bottom: BorderSide(color: ThemeConfig.separeColor)),
        ),
      ),
      onTap: () => dispatch(UserEditInfoViewActionCreator.onTap('头像')),
    );
    _items.insert(0, _headWidget);
    return Column(
      children: _items,
    );
  }

  return Scaffold(
    appBar: myAppBar(viewService.context, title: '我的资料'),
    body: SingleChildScrollView(
      child: Column(
        children: <Widget>[
          _body(),
          Container(
            margin: EdgeInsets.only(left: 15, right: 15, top: 100),
            height: 50,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.all(Radius.circular(4)),
              color: ThemeConfig.mainColor,
            ),
            child: InkWell(
              child: Center(
                child: Text(
                  '保存',
                  style: TextThemeConfig.Font16WithWhite,
                ),
              ),
              onTap: () => dispatch(UserEditInfoViewActionCreator.onSubmit()),
            ),
          ),
        ],
      ),
    ),
  );
}
